package mainServer;

import interaction.BDConnection;
import interaction.BDDisconnect;

import java.util.HashMap;

public abstract class DefaultServer implements IServer
{
   protected HashMap<Integer, Client> m_clients = new HashMap<Integer, Client>();
  

  @Override
  public java.util.Collection<Client> getClients()
  {
    return m_clients.values();
  }
    
    
  protected Integer addClient(BDConnection query)
  {
    Client client = new Client();
    
    query.m_clientId = client.getId();
    m_clients.put(client.getId(), client);
    
    System.out.println("Зарегистрирован клиент с id " + query.m_clientId.toString());
    
    return client.getId();
  }
  
  protected void removeClient(BDDisconnect query)
  {
    if(m_clients.containsKey(query.m_clientId))
    {
      m_clients.remove(query.m_clientId);
      System.out.println("Удалён клиент с id " + query.m_clientId.toString());
    }
    else
      System.out.println("Попытка удаления удалённого клиента id " + query.m_clientId.toString());
  }
  
}
